package com.tjtt.tdm.system.dao.impl;

import java.util.List;
import java.util.Map;

import org.hibernate.Query;

import com.tjtt.tdm.base.HibernateEntityDAO;
import com.tjtt.tdm.base.PageResult;
import com.tjtt.tdm.exception.DaoException;
import com.tjtt.tdm.system.dao.RightGiveDao;

public class RightGiveDaoImpl extends HibernateEntityDAO implements RightGiveDao {
	
	@Override
	public void exeSql(String strSql) {
		try {
			this.executeSQL(strSql);
		} catch (DaoException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public List getSql(String strSql) {
		Query query = getSession().createSQLQuery(strSql);
		List lists = query.list();
		return lists;
	}

	@Override
	public PageResult queryRightGiveList(Map filterMap) {
		StringBuffer queryString = new StringBuffer();
		StringBuffer queryCountString = new StringBuffer();
		
		queryCountString.append("select count(*) from SYS_RIGHT_GIVE where 1=1 ");
		queryString.append("select ID,SOURCEPERSONNAME,TARGETPERSONNAME,BEGINDATE,ENDDATE from SYS_RIGHT_GIVE where 1=1 ");
		if (filterMap!= null && !filterMap.isEmpty()) {
			if(null != filterMap.get("sourcepersonname") &&! "".equals(filterMap.get("sourcepersonname"))){
				queryString.append("and SOURCEPERSONNAME like '%" +  filterMap.get("sourcepersonname") + "%' ");
				queryCountString.append("and SOURCEPERSONNAME like '%" +  filterMap.get("sourcepersonname") + "%' ");
			}
			String sidx = (String) filterMap.get("sidx");
			String sord = (String) filterMap.get("sord");
			queryString.append("order by " + sidx + " " + sord + " ");
		}
		return searchBySQL(queryCountString.toString(), queryString.toString(), filterMap);
	}

}
